package net.qiyuesuo.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.qiyuesuo.service.FileService;
import net.qiyuesuo.service.impl.FileServiceImpl;

/**
 * 删除文件接口
 */
public class DeleteFileServlet extends HttpServlet{
	
	private static final long serialVersionUID = 1L;
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	private FileService fileService = new FileServiceImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		String fileKey = req.getParameter("fileKey");
		fileService.deleteFile(fileKey);
		try(ServletOutputStream output = res.getOutputStream()){
			String result = new String("删除文件："+fileKey+"成功。");
			output.write(result.getBytes());
			output.flush();
		}
		logger.info("删除文件："+fileKey);
	}

	
}
